﻿
--|--------------------------------------------------------------------------------
--| [GetMarkerInfo] - Insert Procedure Script for GPSPoint
--|--------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[GetMarkerInfo]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) 
  DROP PROCEDURE [dbo].[GetMarkerInfo]
GO

CREATE PROCEDURE [dbo].[GetMarkerInfo]
(
	@GameID int,
	@EntityID int
)
AS
	SET NOCOUNT ON
	DECLARE @ID int
	
	SELECT @ID = Max(ID) FROM [GPSPoint] WHERE GameID = @GameID AND EntityID = @EntityID

	SELECT
		[EntityID] as ID,
		E.[Name] as [Name],
		E.[Description] as [Description],
		[Latitude],
		[Longitude],
		[Time],
		[Speed],
		[Altitude],
		Datediff(s,P.[Time], GetDate()) as Delay
	FROM [GPSPoint] P
	JOIN [Entity] E ON E.ID = P.EntityID
	WHERE
		P.[ID] = @ID
	
GO
  